﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using BOL;
using BOL.UI;
using UtilityExtensions;
using System.Web.UI.DataVisualization.Charting;
using System.Data.SqlClient;
using Website.Logger;
using System.Web.UI.HtmlControls;
using System.Drawing;

namespace UILGestion.VentaAdmin.Chart
{
    public partial class Chart01 : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {

                if (!this.IsPostBack)
                {
                    idProyecto.Value = (string)Request.QueryString["idProyecto"];
                    FormatForm();
                }
            }
            catch (SqlException sqlex)
            {
                WebServerSideSqlError.Log(sqlex);
                ScriptManager.RegisterClientScriptBlock(this, typeof(Page),
                 "uniqueKey" + DateTime.Now, "alert('" + sqlex.Message.Replace("'", "") + "');", true);


            }
            catch (Exception ex)
            {
                WebServerSideError.Log(ex);
                ScriptManager.RegisterClientScriptBlock(this, typeof(Page),
                 "uniqueKey" + DateTime.Now, "alert('" + ex.Message.Replace("'", "") + "');", true);

            }
        }


        public void FormatForm()
        {

           


        }
        public void LoadChart(int idProyecto,int tipoUI)
        {

            var bol = new UIBL();

            var instalacionPeriodo = bol.GetVentaResumen(idProyecto,tipoUI).OrderBy(p=>p.nombre).ToList();

            var totales = new UIResumenInfo();
            totales.esTotal = true;
            totales.nombre = "TOTAL:";
            totales.total = instalacionPeriodo.Sum(p => p.total);
            totales.bloqueado=instalacionPeriodo.Sum(p=>p.bloqueado);
            totales.venta = instalacionPeriodo.Sum(p=>p.venta);
            totales.separado = instalacionPeriodo.Sum(p => p.separado);
            instalacionPeriodo.Add(totales);
            
            itemGridView.DataSource = instalacionPeriodo;
            itemGridView.DataBind();
            
        }

        protected void itemGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
        {
            //e.Row.Cells[0].BackColor = Color.FromName("#99CCFF");

            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                bool esTotal= ((UIResumenInfo)(e.Row.DataItem)).esTotal;

                
                if (esTotal)   
                {
                    e.Row.BackColor = Color.LightYellow;
                    e.Row.Font.Bold=true;
                }
                //ff000c
                

            }
        }
    }
}